package com.dlc.felear.xiaoensale.activity;

import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.dlc.felear.xiaoensale.R;
import com.dlc.felear.xiaoensale.adapter.ShowPicAdapter;
import com.dlc.felear.xiaoensale.customView.ConfirmDialog;
import com.dlc.felear.xiaoensale.customView.LoadingDialog;
import com.dlc.felear.xiaoensale.deviceUtil.TopbarHelper;
import com.dlc.felear.xiaoensale.utils.MenuPicUtil;
import com.itdlc.android.library.base.BaseActivity;

import java.util.List;

import butterknife.BindView;

/**
 * 菜谱图片管理
 */
public class MenuPicDataActivity extends BaseActivity implements ConfirmDialog.ConfirmDialogCallback{
    private static final String TAG = "MenuPicDataActivity";
    private TopbarHelper topbarHelper;
    @BindView(R.id.cp_gv1)
    GridView gridView;
    private LoadingDialog loadingDialog;
    private ShowPicAdapter showPicAdapter;
    private String picPath= Environment.getExternalStorageDirectory() + "/zkyc/pic/";
    private ConfirmDialog confirmDialog;
    private String tempName;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_update_base_data;
    }

    @Override
    protected void initialView() {
        topbarHelper = new TopbarHelper(this);
        topbarHelper.setTitle("菜谱图片管理");
        topbarHelper.setcon(R.drawable.arrow_left);
        topbarHelper.setNavActivity(ParamerSettingActivity.class);
        loadingDialog = new LoadingDialog(this, "正在执行..");
        showPicAdapter = new ShowPicAdapter(this);
        gridView.setAdapter(showPicAdapter);
        confirmDialog=new ConfirmDialog(this,this);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                tempName=showPicAdapter.getItem(position);
                confirmDialog.showDialog("是否重新下载图片");
            }
        });
    }

    @Override
    protected void initData() {
        showPicAdapter.setItems(getPicPaths());
    }



    public  List<String> getPicPaths() {
        return MenuPicUtil.getInstance(this).getPicsName();
    }




    @Override
    public void selectResult(int value, int id) {
        if(value==1){
            showPicAdapter.removeData(tempName);
            MenuPicUtil.getInstance(this).addDownLoadPicTask(tempName,true);
        }
    }
}